@import 'variables';

@mixin range-widget {
    color: var(--jj-bg-secondary);
    --thumb-height: 0.875em;
    --track-height: 0.125em;
    --track-color: var(--jj-bg-tertiary);
    --brightness-hover: 130%;
    --brightness-down: 80%;
    --clip-edges: 0.125em;

    /* === range commons === */

    & {
        position: relative;
        background: none;
        overflow: hidden;
        padding: 6px 0;
    }

    &:active {
        cursor: grabbing;
    }

    &:disabled {
        filter: grayscale(1);
        opacity: 0.3;
        cursor: not-allowed;
    }

    /* === WebKit specific styles === */

    &,
    &::-webkit-slider-runnable-track,
    &::-webkit-slider-thumb {
        -webkit-appearance: none;
        transition: all ease 100ms;
        height: var(--thumb-height);
    }

    &::-webkit-slider-runnable-track,
    &::-webkit-slider-thumb {
        position: relative;
    }

    &::-webkit-slider-thumb {
        --thumb-radius: calc((var(--thumb-height) * 0.5) - 1px);
        --clip-top: calc((var(--thumb-height) - var(--track-height)) * 0.5 - 0.5px);
        --clip-bottom: calc(var(--thumb-height) - var(--clip-top));
        --clip-further: calc(100% + 1px);
        --box-fill: calc(-100vmax - var(--thumb-width, var(--thumb-height))) 0 0 100vmax currentColor;

        width: var(--thumb-width, var(--thumb-height));
        background: linear-gradient(currentColor 0 0) scroll no-repeat left center / 50% calc(var(--track-height) + 1px);
        background-color: currentColor;
        box-shadow: var(--box-fill);
        border-radius: var(--thumb-width, var(--thumb-height));

        filter: brightness(100%);
        clip-path: polygon(100% -1px,
                var(--clip-edges) -1px,
                0 var(--clip-top),
                -100vmax var(--clip-top),
                -100vmax var(--clip-bottom),
                0 var(--clip-bottom),
                var(--clip-edges) 100%,
                var(--clip-further) var(--clip-further));
    }

    &:hover::-webkit-slider-thumb {
        filter: brightness(var(--brightness-hover));
        cursor: grab;
    }

    &:active::-webkit-slider-thumb {
        filter: brightness(var(--brightness-down));
        cursor: grabbing;
    }

    &::-webkit-slider-runnable-track {
        background: linear-gradient(var(--track-color) 0 0) scroll no-repeat center / 100% calc(var(--track-height) + 1px);
    }

    &:disabled::-webkit-slider-thumb {
        cursor: not-allowed;
    }

    /* === Firefox specific styles === */

    &,
    &::-moz-range-track,
    &::-moz-range-thumb {
        appearance: none;
        transition: all ease 100ms;
        height: var(--thumb-height);
    }

    &::-moz-range-track,
    &::-moz-range-thumb,
    &::-moz-range-progress {
        background: #fff0;
    }

    &::-moz-range-thumb {
        background: currentColor;
        border: 0;
        width: var(--thumb-width, var(--thumb-height));
        border-radius: var(--thumb-width, var(--thumb-height));
        cursor: grab;
    }

    &:active::-moz-range-thumb {
        cursor: grabbing;
    }

    &::-moz-range-track {
        width: 100%;
        background: var(--track-color);
    }

    &::-moz-range-progress {
        appearance: none;
        background: currentColor;
        transition-delay: 30ms;
    }

    &::-moz-range-track,
    &::-moz-range-progress {
        height: calc(var(--track-height) + 1px);
        border-radius: var(--track-height);
    }

    &::-moz-range-thumb,
    &::-moz-range-progress {
        filter: brightness(100%);
    }

    &:hover::-moz-range-thumb,
    &:hover::-moz-range-progress {
        filter: brightness(var(--brightness-hover));
    }

    &:active::-moz-range-thumb,
    &:active::-moz-range-progress {
        filter: brightness(var(--brightness-down));
    }

    &:disabled::-moz-range-thumb {
        cursor: not-allowed;
    }
}

@mixin checkbox-widget {
    width: 20px;
    height: 20px;
    position: relative;
    border-radius: var(--jj-border-radius-small);
    margin: 0;

    input[type='checkbox'] {
        appearance: none;
        -webkit-appearance: none;
        -moz-appearance: none;

        &:after {
            cursor: pointer;
            line-height: 1.5em;
            content: ' ';
            display: block;
            position: absolute;
            top: 0;
            left: 0;
            box-sizing: border-box;
            width: 100%;
            height: 100%;
            background: var(--jj-bg-quaternary);
            border: 1px solid var(--jj-border-secondary);
            border-radius: var(--jj-border-radius-small);
        }

        &:checked:after {
            content: url('/assets/widgets/icon-checkbox-tick.svg');
            text-align: center;
        }
    }
}

@mixin color-picker-widget {
    appearance: none;
    -moz-appearance: none;
    -webkit-appearance: none;
    background: none;
    width: 16px;
    height: 16px;
    border: 0;
    cursor: pointer;
    padding: 0;
    border: 1px solid var(--jj-border-quaternary);
    border-radius: var(--jj-border-radius-small);
    overflow: hidden;
}

// color-picker-widget
::-webkit-color-swatch-wrapper {
    padding: 0;
}

::-webkit-color-swatch{
    border: 0;
    border-radius: 0;
}

::-moz-color-swatch,
::-moz-focus-inner{
    border: 0;
}

::-moz-focus-inner{
    padding: 0;
}

.joint-widget.joint-theme-light {
    border-radius: var(--jj-border-radius-small);
    transition: background-color 0.2s ease-in-out;

    &:hover:not([data-type="separator"]):not(:disabled) {
        background-color: var(--jj-accent-hover);
    }

    &[data-type="separator"] {
        width: 0px;
        border-color: var(--jj-border-tertiary);
    }

    &[data-name="undo"],
    &[data-name="redo"] {
        width: 40px;
        height: 40px;
        background: transparent;
        border: none;
        cursor: pointer;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    &[data-name="undo"] {

        &::before {
            content: url('/assets/widgets/icon-undo.svg');
        }
    }

    &[data-name="redo"] {

        &::before {
            content: url('/assets/widgets/icon-redo.svg');
        }
    }

    & input[type="range"] {
        margin-right: 8px;
        @include range-widget;
    }

    &[data-type="checkbox"] {
        @include checkbox-widget;
    }

    &[data-type="colorPicker"] {
        @include color-picker-widget;
        width: 24px;
        height: 24px;
    }

    &:disabled {
        filter: opacity(0.5);
        cursor: initial;
    }
}
